//
//  HJTabBarController.m
//  newOcWeibo
//
//  Created by heJing on 15/7/20.
//  Copyright (c) 2015年 heima. All rights reserved.
//

#import "HJTabBarController.h"
//#import "HJDiscoverController.h"
//#import "HJHomeController.h"
//#import "HJMessageController.h"
//#import "HJProfileController.h"

@interface HJTabBarController ()

@end

@implementation HJTabBarController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
//    HJLog(@"%@",self.viewControllers);
    
//    //ios8, xcode6.3之后不让我们设置tabbar
//    for (UIView *view in self.viewControllers) {
//        view.frame = CGRectMake(0, 0, 100, 100);
//    }
}


- (void)viewDidLoad {
    [super viewDidLoad];

    // 首页
    [self addChildVCWithSBName:@"HJHomeController" title:@"首页" norImageName:@"tabbar_home" selectedImageName:@"tabbar_home_highlighted"];
    // 消息
    [self addChildVCWithSBName:@"HJMessageController" title:@"消息" norImageName:@"tabbar_message_center" selectedImageName:@"tabbar_message_center_highlighted"];
    // 发现
    [self addChildVCWithSBName:@"HJDiscoverController" title:@"发现" norImageName:@"tabbar_discover" selectedImageName:@"tabbar_discover_highlighted"];
    // 我
    [self addChildVCWithSBName:@"HJProfileController" title:@"我" norImageName:@"tabbar_profile" selectedImageName:@"tabbar_profile_highlighted"];

}

- (void)addChildVCWithSBName:(NSString *)sbName  title:(NSString *)title norImageName:(NSString *)norImageName selectedImageName:(NSString *)selectedImageName{
    
    // 1.加载Storyboard
    UIStoryboard *sb = [UIStoryboard storyboardWithName:sbName bundle:nil];
    // 2.创建Storyboard中的初始控制器
    UINavigationController *nav = sb.instantiateInitialViewController;
    // 3.调用addChildVCWithController
    [self addChildVCWithController:nav.topViewController title:title norImageName:norImageName selectedImageName:selectedImageName];
}

- (void)addChildVCWithController:(UIViewController *)vc  title:(NSString *)title norImageName:(NSString *)norImageName selectedImageName:(NSString *)selectedImageName{
    
    //    self.tabBar.tintColor = [UIColor redColor];
    // 设置标题
    vc.tabBarItem.title = title;
    vc.navigationItem.title = title;
    // 设置默认图片
    vc.tabBarItem.image = [UIImage imageNamed:norImageName];
    // 设置选中图片
    UIImage *selectedImage =  [UIImage imageNamed:selectedImageName];
    // 告诉系统不要渲染图片
    // 注意: 在images.xcassets中设置对于iOS7无效
    //    selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.selectedImage = selectedImage;
    
    // 设置选项卡标题的颜色
    //    [vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor orangeColor]} forState:UIControlStateSelected];
    //    self.tabBar.tintColor = [UIColor orangeColor];
    
    // 设置随机色
    vc.view.backgroundColor = HJRandomColor;
    // 添加到父控件
    [self addChildViewController:vc.navigationController];
}





@end
